package com.lonely.system.enums;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author: 黄志标
 * @date: 2025/5/27 13:34
 * @description: 工厂产线相关的枚举
 */
public class SysProductionLineEnum {


    /**
     * 产线类型枚举
     */
    public enum ProductionLineType {

        /**
         * 职能组
         */
        FUNCTION_GROUP(1),

        /**
         * 裁剪组
         */
        TAILOR_GROUP(2),

        /**
         * 车缝组
         */
        SEWING_GROUP(3),

        /**
         * 后整组
         */
        POST_WHOLE_GROUP(4),
        ;

        /**
         * 工厂类型
         */
        public final int type;

        ProductionLineType(int type) {
            this.type = type;
        }


        /**
         * 根据工厂类型获取工厂类型枚举
         *
         * @param type
         * @return
         */
        public static ProductionLineType getInstance(int type) {
            return Arrays.stream(ProductionLineType.values()).filter(x -> Objects.equals(x.type, type)).findFirst().orElse(null);
        }
    }


    /**
     * 产线状态枚举
     */
    public enum ProductionLineStatus {

        /**
         * 启用
         */
        ENABLE(0),

        /**
         * 停用
         */
        DISABLE(1),

        /**
         * 停单
         */
        SUSPEND_SPLIT_ORDERS(2),
        ;

        /**
         * 状态
         */
        public final int status;

        ProductionLineStatus(int status) {
            this.status = status;
        }
    }


    /**
     * 生产工种枚举
     */
    public enum WorkTypeEnum {

        /**
         * 跟单文员
         */
        MERCHANDISING_CLERK(ProductionLineType.FUNCTION_GROUP, 1, "跟单文员"),


        /**
         * 采购
         */
        PURCHASE(ProductionLineType.FUNCTION_GROUP, 2, "采购"),


        /**
         * 领料
         */
        PICKING(ProductionLineType.FUNCTION_GROUP, 3, "领料"),


        /**
         * 仓储
         */
        STORAGE(ProductionLineType.FUNCTION_GROUP, 4, "仓储"),


        /**
         * 财务
         */
        FINANCE(ProductionLineType.FUNCTION_GROUP, 5, "财务"),


        /**
         * 发货
         */
        SEND_OUT_GOODS(ProductionLineType.FUNCTION_GROUP, 6, "发货"),


        /**
         * 全查
         */
        FULL_SEARCH(ProductionLineType.FUNCTION_GROUP, 7, "全查"),


        /**
         * QC
         */
        QC(ProductionLineType.FUNCTION_GROUP, 8, "QC"),


        /**
         * 中查
         */
        ZHONG_CHA(ProductionLineType.FUNCTION_GROUP, 9, "中查"),


        /**
         * AGV管理员
         */
        AGV_ADMINISTRATOR(ProductionLineType.FUNCTION_GROUP, 10, "AGV管理员"),

        /**
         * 排唛
         */
        MARKING_ARRANGEMENT(ProductionLineType.TAILOR_GROUP, 11, "排唛"),


        /**
         * 剪裁
         */
        CUT_OUT(ProductionLineType.TAILOR_GROUP, 12, "剪裁"),


        /**
         * 平车
         */
        FLAT_CAR(ProductionLineType.SEWING_GROUP, 13, "平车"),

        /**
         * 冚车
         */
        THE_CAR(ProductionLineType.SEWING_GROUP, 14, "冚车"),

        /**
         * 打边
         */
        BEAT_THE_EDGE(ProductionLineType.SEWING_GROUP, 15, "打边"),

        ;

        /**
         * 产线分组类型
         */
        public final ProductionLineType plGroupType;

        /**
         * 工种类型
         */
        public final int workType;

        /**
         * 工种名称
         */
        public final String workTypeName;


        WorkTypeEnum(ProductionLineType plGroupType, int workType, String workTypeName) {
            this.plGroupType = plGroupType;
            this.workType = workType;
            this.workTypeName = workTypeName;
        }


        /**
         * 根据产线类型获取该类型下的所有工种
         *
         * @param plType
         * @return
         */
        public static List<WorkTypeEnum> getWorkTypeEnumByPlType(int plType) {
            ProductionLineType productionLineType = ProductionLineType.getInstance(plType);
            if (productionLineType == null) {
                return new ArrayList<>();
            }
            return Arrays.stream(WorkTypeEnum.values()).filter(x -> Objects.equals(x.plGroupType, productionLineType)).collect(Collectors.toList());
        }
    }

}
